package com.xyht.sca_s.student_manage_system.modules.stampManagement.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.stampManagement.entity.dto.SmsStampAddDto;
import com.xyht.sca_s.student_manage_system.modules.stampManagement.entity.dto.SmsStampDeletedDto;
import com.xyht.sca_s.student_manage_system.modules.stampManagement.entity.dto.SmsStampUpdateDto;
import com.xyht.sca_s.student_manage_system.modules.stampManagement.service.SmsStampManagementService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 印章管理 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-05-31
 */
@RestController
@RequestMapping("/stampManagement")
@SecretBody
public class SmsStampManagementController {

    @Resource
    private SmsStampManagementService smsStampManagementService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("添加印章")
    @PostMapping("/add")
    public ResponseResult addStamp(@RequestBody @Validated SmsStampAddDto smsStampAddDto, HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsStampManagementService.addStamp(userId,smsStampAddDto);
    }

    @ApiModelProperty("删除印章")
    @PostMapping("/deleted")
    public ResponseResult deletedStamp(@RequestBody SmsStampDeletedDto smsStampDeletedDto,HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsStampManagementService.deletedStamp(smsStampDeletedDto,userId);
    }


    @ApiModelProperty("修改印章")
    @PostMapping("/update")
    public ResponseResult updateStampInfo(@RequestBody SmsStampUpdateDto smsStampUpdateDto, HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsStampManagementService.updateStampInfo(userId,smsStampUpdateDto);
    }

    @ApiModelProperty("获取印章详情")
    @GetMapping("/detail")
    public ResponseResult getStampDetail(@RequestParam(value = "id",required = false)String id,HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsStampManagementService.getStampDetail(id,userId);
    }

    @ApiModelProperty("获取印章列表")
    @GetMapping("/list")
    public ResponseResult getStampList(HttpServletRequest request,
                                       @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                                       @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                       @RequestParam(value = "stampName",required = false)String stampName,
                                       @RequestParam(value = "stampType",required = false)Integer stampType){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsStampManagementService.getStampList(userId,pageSize,pageNum,stampName,stampType);
    }


}

